#region Using

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using XDebugConsole;
using XNgine;
using XNgine.CameraManagement;
using XNgine.CameraManagement.Cameras;
using XNgine.HelperGameComponents;
using XNgine.Input;
using XNgine.ObjectManagement.Infos;
using XNgine.RenderManagement;
using XNgine.ScreenManagement;
using XNgine.ScreenManagement.StandardScreens;
using XNgine.Services;
using XNgine_Test_Game.GameScreens;

#endregion

namespace XNgine_Test_Game
{
    internal static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        private static void Main(string[] args)
        {
            XEngine.EngineSetup = SetupComponentsAndServices;
            XEngine.CreateEngine();
            XEngine.Instance.Run();
        } 

        private static void SetupComponentsAndServices()
        {
            XEngine.Instance.IsMouseVisible = true;

            ScreenManager screenManager = new ScreenManager();
            KeyboardDevice keyboardDevice = new KeyboardDevice();
            MouseDevice mouseDevice = new MouseDevice();
            CameraManager cameraManager = new CameraManager();
            RenderManager renderManager = new RenderManager(new RenderProvider());


            // Register Services
            XEngine.Instance.AddService<IMouseDevice>(mouseDevice);
            XEngine.Instance.AddService<IKeyboardDevice>(keyboardDevice);
            XEngine.Instance.AddService<IScreenManagement>(screenManager);
            XEngine.Instance.AddService<ICameraManagement>(cameraManager);
            XEngine.Instance.AddService<IRenderManagement>(renderManager);

            // Register Components
            XEngine.Instance.Components.Add(keyboardDevice);
            XEngine.Instance.Components.Add(mouseDevice);
            XEngine.Instance.Components.Add(screenManager);
            XEngine.Instance.Components.Add(cameraManager);
            XEngine.Instance.Components.Add(new FPSCounter());

            // Initialize CameraManager
            ICamera camera = new FirstPersonCamera("MainCamera")
                                 {
                                     Position = new Vector3(0, 0, 0),
                                     Target = new Vector3(0, 0,  10)
                                 };
            //ICamera camera = new Camera("MainCamera")
            //                     {
            //                         Position = new Vector3(0, 50, 0),
            //                         Target = new Vector3(0, 0, 0f),
            //                         Up = new Vector3(0, 0, 1)
            //                     };
            cameraManager.AddCamera(camera);

            mouseDevice.Freeze = true;

            var console=XEngine.Instance.GetService<IConsole>();
            console.Enabled = true;

            // Initialize ScreenManager
            IGameScreen cbg = new TextureBackgroundScreen();
            MainMenu mm = new MainMenu("Test Game");

            LoadingScreen.Load(false, false, cbg, mm);
        }
    }
}